<template>
  <PullRefresh v-model="refreshing" @refresh="onRefresh">
  <List v-model:loading="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
    <Cell v-for="item in list" :key="item" :title="item.noticeContent" :value="item.createTime"/>
  </List>
</PullRefresh>
</template>
<script setup>
import { PullRefresh, List, Cell } from 'vant';
import { ref } from 'vue';
import {getList} from '@/server/business/message.js'

const list = ref([]);
const loading = ref(false);
const finished = ref(false);
const refreshing = ref(false);
const userInfo = JSON.parse(localStorage.userInfo)
const params = {
  "noticeType": "",
  "noticeUser": userInfo.pkMember,
  "pageNum": 1,
  "pageSize": 10
}
// 加载
const onLoad = () => {
  if (refreshing.value) {
    list.value = [];
    refreshing.value = false;
  }
  loading.value = true
  getList(params).then(res => {
    list.value.push(...res.rows)
    loading.value = false;
    params.pageNum++
    finished.value = list.value.length >= res.total
  })
}
// 刷新
const onRefresh = () => {
  // 清空列表数据
  finished.value = false;
  params.pageNum = 1
  // 重新加载数据
  // 将 loading 设置为 true，表示处于加载状态
  loading.value = true;
  onLoad();
};
</script>